//
//  ViewController.swift
//  QTools
//
//  Created by zhangqianchu on 2018/11/30.
//  Copyright © 2018年 zhangqianchu. All rights reserved.
//

import Cocoa
import Foundation

class ViewController: NSViewController {
    var appNameStr = "com.p1.mobile.putong";
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    override func viewDidAppear() {
        self.view.window?.title = "QTools"
//        let resources = Bundle.main.resourcePath?.appending("/adb")
//        _initAdbRoot(resources!)// don't work
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }
    
    func getAdbPath() -> String {
        let resources = Bundle.main.resourcePath?.appending("/adb")
        return resources!
    }
    
    func getHomePath() -> String {
        return NSHomeDirectory();
    }
    
    @IBAction func screenCap(_ sender: Any) {
        print("screen cap")
//        let resources = Bundle.main.resourcePath?.appending("/adb")
//        _screencap(getAdbPath(), NSHomeDirectory().appending("/Desktop"));
        _screencap(getHomePath());
    }
    
    @IBAction func pulltraces(_ sender: Any) {
        print("pull traces");
        _pulltraces(getHomePath());
    }
    @IBAction func pullerrors(_ sender: Any) {
        print("pullerrors");
        _pullerrors(getHomePath(), appNameStr);
    }
    
    @IBAction func quickRecord(_ sender: Any) {
        print("quick record");
                
    }
    @IBAction func installapp(_ sender: Any) {
        print("installapp");
        let alert = NSAlert();
        //正文
        alert.messageText = "提示";
        //描述文字
        alert.informativeText = "该功能稍后提供";
        alert.runModal();
        
    }
    @IBAction func uninstallTantan(_ sender: Any) {
        print("uninstallTantan");
    _uninstall(getHomePath(), String.init(appNameStr));
    }
    @IBAction func killprocess(_ sender: Any) {
        print("kill process");
        _killprocess(getHomePath(), String.init(appNameStr));
    }
    
    @IBAction func clearAppData(_ sender: Any) {
        _clearAppData(getHomePath(), String.init(appNameStr));
    }
    @IBAction func getAppMemory(_ sender: Any) {
        _getAppMemeory(getHomePath(), String.init(appNameStr));
//        let homeDirectory = NSHomeDirectory()
//        let resources = Bundle.main.resourcePath?.appending("/adb")
//        
//        print(resources)
       // print(homeDirectory)
    }
    
    @IBAction func monkeyTest(_ sender: Any) {
        _monkeyTest(getHomePath(), String.init(appNameStr));
    }
    // 遗弃方法
    @IBAction func resolveError(_ sender: Any) {
        _resolveError(getHomePath() + "/Documents/Test", "");
    }
}

